package com.chcit.mobile.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.animation.ScaleInAnimation;
import com.chcit.mobile.R;
import com.chcit.mobile.helper.recycler.BaseSelectQuickAdapter;
import com.chcit.mobile.mvp.model.entity.StorageBean;
import java.util.List;
import java.util.WeakHashMap;

public class MoveLocatorAdapter extends BaseSelectQuickAdapter<StorageBean, BaseViewHolder> {


    private final WeakHashMap<Integer, CheckBox> mWeakHashMap = new WeakHashMap<>();
    private View.OnClickListener mOnClickListener;

    public MoveLocatorAdapter(@Nullable List<StorageBean> data) {
        super(R.layout.item_storage_list, data);
        initAnimal();

    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        mOnClickListener = onClickListener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final StorageBean item) {

        final CheckBox checkBox = helper.getView(R.id.box_storage_select);
        int position= helper.getAdapterPosition();
        checkBox.setChecked(mSelectedPositions.get(position));
        mWeakHashMap.put(position,checkBox);
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int i= helper.getAdapterPosition();
                if (isItemChecked(i)) {
                    setItemChecked(i, false);
                } else {
                    setItemChecked(i, true);
                }

                if (mTitleBarView != null) {
                    String msg = "已选择" + getSelectedItem().size() + "/" + mData.size();
                    mTitleBarView.setText(msg);
                }
                notifyItemChanged(i);
            }
        });
        final TextView textView = helper.getView(R.id.tv_storage_deal);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickListener != null) {
                    v.setTag(item);
                    mOnClickListener.onClick(v);
                }
            }
        });
        helper.setText(R.id.tv_storage_GuaranteeDate, item.getGuaranteeDate());
        helper.setText(R.id.tv_storage_Lot, item.getLot());
        helper.setText(R.id.tv_storage_productCode, item.getProductCode());
        helper.setText(R.id.tv_storage_manufacturer, item.getManufacturer());
        helper.setText(R.id.tv_storage_pname, item.getProductName());
        helper.setText(R.id.tv_storage_movementDate, item.getGuaranteeDate());
        helper.setText(R.id.tv_storage_locator, item.getLocatorName());
        helper.setText(R.id.tv_storage_VendorName, item.getVendorName());
       // helper.setText(R.id.tv_storage_movementQty, item.get() + "");
        helper.setText(R.id.tv_storage_productSpec, item.getProductSpec());

    }

    void initAnimal(){
        openLoadAnimation(new ScaleInAnimation(0.8f));
        isFirstOnly(false);
    }


}
